package tw.spring.demo.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author 陈艺博
 * @date 2021-02-17 11:25
 * @description Swagger配置类
 **/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("API文档标题title")
                .description("简单优雅的restfun风格description")
                .termsOfServiceUrl("http://www.0313.tw")
                .contact(new Contact("yibo", "http://www.0313.tw", "yibo@0313.tw"))
                .license("许可证")
                .licenseUrl("许可证地址")
                .version("版本1.0")
                .build();
    }

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //扫描basePackage包下面的“/rest/”路径下的内容作为接口文档构建的目标
                .apis(RequestHandlerSelectors.basePackage("tw.spring.demo"))
                .paths(Predicates.or(PathSelectors.regex("/.*")))
                .build();

    }
}